package com.greatwqs.wmall.common.module.exception;

import com.greatwqs.wmall.common.module.constants.HttpStatus;

import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 异常信息枚举
 *
 * @author wang-qingsong
 */
@Getter
@NoArgsConstructor
public enum ErrorCode {

    SUCCESS(HttpStatus.OK, 200),
    BAD_REQUEST(HttpStatus.BAD_REQUEST, 400),
    UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 401),
    FORBIDDEN(HttpStatus.FORBIDDEN, 403),
    NOT_FOUND(HttpStatus.NOT_FOUND, 404),
    METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, 405),
    CONFLICT(HttpStatus.CONFLICT, 409),
    UNSUPPORTED_MEDIA_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, 415),
    INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 500),

    // 1000 - 1999 为用户模块异常
    USER_NOT_FOUND(HttpStatus.BAD_REQUEST, 1001),
    USER_LOGIN_PASSWORD_ERROR(HttpStatus.BAD_REQUEST, 1002),
    LOGIN_AUTH_NOT_FOUND_OR_EXPIRED(HttpStatus.INTERNAL_SERVER_ERROR, 1003),
    USER_LOGIN_ID_ALREADY_EXIST(HttpStatus.BAD_REQUEST, 1004),

    // 2000 - 2999 为商品模块异常
    PRODUCT_NOT_FOUND(HttpStatus.BAD_REQUEST, 2000),
    PRODUCT_STOCK_NOT_ENOUGH(HttpStatus.BAD_REQUEST, 2001),
    PRODUCT_SUB_STOCK_FAILED(HttpStatus.BAD_REQUEST, 2002),

    // 3000 - 3999 为订单模块异常
    ORDER_NOT_EXIST(HttpStatus.BAD_REQUEST, 3000),
    ORDER_CREATE_FAIL(HttpStatus.BAD_REQUEST, 3001);

    // http 响应码
    private int httpStatus;

    // 自定义业务响应码
    private int appCode;

    ErrorCode(int httpStatus, int appCode) {
        this.httpStatus = httpStatus;
        this.appCode = appCode;
    }

    public String getI18nKey() {
        return "error.code." + this.appCode;
    }
}
